package com.zp.testpractice.learnTest.dagger;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import com.zp.testpractice.R;

import javax.inject.Inject;

/**
 * @author izp on 2017/11/11.
 */

public class DaggerActivity extends AppCompatActivity {
    /**
     * 成员注入Field injection，需配合在当前类对的初始化方法中添加appComponent.inject(this); //<=
     */
    @Inject
    DaggerPresenter mDaggerPresenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger);
//        成员注入
        ComponentHolder.getAppComponent().inject(this);
        findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = ((EditText) findViewById(R.id.username)).getText().toString();
                String password = ((EditText) findViewById(R.id.password)).getText().toString();
//                它就直接被注入了
                mDaggerPresenter.login(username, password);
            }
        });
    }
}
